<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

<script>
// 数据类型转换通常指将其他数据类型转成 字符串 数字 布尔值
// 数据类型转换有两种: 强制转换(显式转换) 和 自动转换(隐式转换)

// 强制转换(显式转换): 其他类型 转成 布尔值
var str1 = '';// 空串
var str2 = 'hello';// 非空串
var num1 = 0;// 0
var num2 = 123;// 非0
var num3 = NaN;
var boo1 = true;
var boo2 = false;
var nul = null;
var und = undefined;
var obj = {a:1,b:2};
var fun = function (){};
var arr1 = [];
var arr2 = [6];
var arr3 = [7,8,9];

// Boolean(val) 将val转成布尔值
console.log( Boolean(str1) );// false *
console.log( Boolean(str2) );// true
console.log( Boolean(num1) );// false *
console.log( Boolean(num2) );// true
console.log( Boolean(num3) );// false *
console.log( Boolean(boo1) );// true
console.log( Boolean(boo2) );// false *
console.log( Boolean(nul) );// false *
console.log( Boolean(und) );// false *
console.log( Boolean(obj) );// true
console.log( Boolean(fun) );// true
console.log( Boolean(arr1) );// true
console.log( Boolean(arr2) );// true
console.log( Boolean(arr3) );// true

// 转布尔值的规律: '' 0 NaN false null undefined 转为false,其他都是true


</script>
</body>
</html>